const app = getApp();
const companyName = app.globalData.companyName;
Page({
  data: {
    code: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},
  inputCode: function(e) {
    this.setData({
      code: e.detail.value
    })
  },
  changePhone: function() {
    wx.navigateTo({
      url: '/pages/updatePhone/updatePhone'
    })
  },
  changePassword: function() {
    wx.navigateTo({
      url: '/pages/updatePassword/updatePassword'
    })
  },
  login: function() {
    const code = this.data.code;
    const url = app.globalData.url;
    if (code.length == 0) {
      wx.showToast({
        title: '请输入密码',
        icon: 'none'
      });
      return;
    }
    wx.request({
      url: url + '/management/adminLogin',
      data: {
        companyName,
        password: code
      },
      method: 'POST',
      success: function(response) {
        if (response.data.success) {
          wx.navigateBack({
            delta: 1
          });
          app.globalData.adminLogin = true;
          wx.showToast({
            title: '登录成功',
            icon: 'none'
          });
        } else {
          wx.showToast({
            title: response.data.message || '密码错误',
            icon: 'none'
          });
        }
      }
    })
  }
})